<template>
  <div>
    <van-nav-bar
      title="登录"
      left-text="返回"
      right-text="新用户?"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-form >
      <van-field
        v-model="name"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="pword"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" @click="checkForm"
          >登录</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>

export default {
  data() {
    return {
      name: "",
      pword: "",
      nameState: "",
      pwdState: "",
    };
  },
  methods: {
    onClickLeft() {
      console.log(this.$router);
      this.$router.go(-1)
    },
    onClickRight() {
      this.$router.push('/i')
    },
    checkForm(){
      let url=`ename=${this.name}&pword=${this.pword}`
      this.axios.post('/login',url).then(res=>{
        console.log(res);
        if(res.data.code==200){ // 
            this.$store.commit('updateName',this.name)
            this.$router.push('/')
            
          }else {  // 
            this.Dialog({ message: '密码不一致' });
          }
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
